/* -*- mode: c++ -*- */
/****************************************************************************
 *****                                                                  *****
 *****                   Classification: UNCLASSIFIED                   *****
 *****                    Classified By:                                *****
 *****                    Declassify On:                                *****
 *****                                                                  *****
 ****************************************************************************
 *
 *
 * Developed by: Naval Research Laboratory, Tactical Electronic Warfare Div.
 *               EW Modeling & Simulation, Code 5773
 *               4555 Overlook Ave.
 *               Washington, D.C. 20375-5339
 *
 * License for source code can be found at:
 * https://github.com/USNavalResearchLaboratory/simdissdk/blob/master/LICENSE.txt
 *
 * The U.S. Government retains all rights to use, duplicate, distribute,
 * disclose, or release this software.
 *
 */
#ifndef SIMCORE_COMMON_VERSION_H
#define SIMCORE_COMMON_VERSION_H

#include <string>
#include "simCore/Common/Export.h"
#include "simCore/Common/Exception.h"

// ***********************************************************************
// * simCore/Common/Version.h is auto-generated.  Do not edit this file. *
// ***********************************************************************

#define SIMDIS_SDK_VERSION_MAJOR @SIMDIS_SDK_MAJOR_VERSION@
#define SIMDIS_SDK_VERSION_MINOR @SIMDIS_SDK_MINOR_VERSION@
#define SIMDIS_SDK_VERSION_REVISION @SIMDIS_SDK_REVISION_VERSION@
#define SIMDIS_SDK_SOVERSION @SIMDIS_SDK_SOVERSION@

namespace simCore
{
  /** SIMDIS SDK major version number */
  static const int SDKVERSION_MAJOR = SIMDIS_SDK_VERSION_MAJOR;
  /** SIMDIS SDK minor version number */
  static const int SDKVERSION_MINOR = SIMDIS_SDK_VERSION_MINOR;
  /** SIMDIS SDK revision version number */
  static const int SDKVERSION_REVISION = SIMDIS_SDK_VERSION_REVISION;
  /** SIMDIS SDK shared object version (SOVERSION) */
  static const int SDKVERSION_SOVERSION = SIMDIS_SDK_SOVERSION;

  /** Retrieves the SDKVERSION_MAJOR in the compiled library */
  SDKCORE_EXPORT int majorVersion();
  /** Retrieves the SDKVERSION_MINOR in the compiled library */
  SDKCORE_EXPORT int minorVersion();
  /** Retrieves the SDKVERSION_REVISION in the compiled library */
  SDKCORE_EXPORT int revisionVersion();
  /** Retrieves the SDKVERSION_SOVERSION in the compiled library */
  SDKCORE_EXPORT int soVersion();
  /** Retrieves the compiled-in version string (Major.Minor.Revision) */
  SDKCORE_EXPORT std::string versionString();

  /**
   * Checks the soversion (for binary compatibility) for API differences between what was
   * compiled against, vs what is being linked against.  This will help track down errors
   * during active development, especially on Windows systems.
   * The check works by compiling the version information into the DLL (or .so) and
   * comparing the compiled-in version information against the compiled-against version
   * information in this header, specifically in this inline function.
   * @return 0 on no errors with version; 1 when there's some sort of version mismatch
   */
  inline int checkVersion()
  {
    return (SDKVERSION_SOVERSION == soVersion()) ? 0 : 1;
  }

  /** Declare library version error exception to throw */
  SIMCORE_EXCEPTION(LibraryVersionError);

  /** Version of checkVersion that throws an exception when incompatible with loaded version */
  inline void checkVersionThrow()
  {
    if (simCore::checkVersion() != 0)
      throw(SIMCORE_MAKE_EXCEPTION(LibraryVersionError, " Version number mismatch against SDK library"));
  }
}

/* Convenience macro that can be used to decide whether a feature is present or not i.e.
 * #if SIMDIS_SDK_MIN_VERSION_REQUIRED(1,6,0)
 *    your code here
 * #endif
 */
#define SIMDIS_SDK_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((SIMDIS_SDK_VERSION_MAJOR>MAJOR) || (SIMDIS_SDK_VERSION_MAJOR==MAJOR && (SIMDIS_SDK_VERSION_MINOR>MINOR || (SIMDIS_SDK_VERSION_MINOR==MINOR && SIMDIS_SDK_VERSION_REVISION>=PATCH))))
#define SIMDIS_SDK_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((SIMDIS_SDK_VERSION_MAJOR<MAJOR) || (SIMDIS_SDK_VERSION_MAJOR==MAJOR && (SIMDIS_SDK_VERSION_MINOR<MINOR || (SIMDIS_SDK_VERSION_MINOR==MINOR && SIMDIS_SDK_VERSION_REVISION<PATCH))))
#define SIMDIS_SDK_VERSION_LESS_OR_EQUAL(MAJOR, MINOR, PATCH) ((SIMDIS_SDK_VERSION_MAJOR<MAJOR) || (SIMDIS_SDK_VERSION_MAJOR==MAJOR && (SIMDIS_SDK_VERSION_MINOR<MINOR || (SIMDIS_SDK_VERSION_MINOR==MINOR && SIMDIS_SDK_VERSION_REVISION<=PATCH))))
#define SIMDIS_SDK_VERSION_GREATER_THAN(MAJOR, MINOR, PATCH) ((SIMDIS_SDK_VERSION_MAJOR>MAJOR) || (SIMDIS_SDK_VERSION_MAJOR==MAJOR && (SIMDIS_SDK_VERSION_MINOR>MINOR || (SIMDIS_SDK_VERSION_MINOR==MINOR && SIMDIS_SDK_VERSION_REVISION>PATCH))))
#define SIMDIS_SDK_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((SIMDIS_SDK_VERSION_MAJOR>MAJOR) || (SIMDIS_SDK_VERSION_MAJOR==MAJOR && (SIMDIS_SDK_VERSION_MINOR>MINOR || (SIMDIS_SDK_VERSION_MINOR==MINOR && SIMDIS_SDK_VERSION_REVISION>=PATCH))))

#endif /* SIMCORE_COMMON_VERSION_H */
